package com.faner.fast.upms.service.impl;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.faner.fast.base.PageDTO;
import com.faner.fast.upms.domain.dto.SysLogDTO;
import com.faner.fast.upms.model.SysLogDO;
import com.faner.fast.upms.mapper.SysLogMapper;
import com.faner.fast.upms.service.SysLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 日志表 服务实现类
 * </p>
 *
 * @author faner
 * @since 2021-01-22
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLogDO> implements SysLogService {

    @Override
    public Page<SysLogDO> getLogByPage(PageDTO page, SysLogDTO sysLog) {
        LambdaQueryWrapper<SysLogDO> wrapper = Wrappers.lambdaQuery();
        if (StrUtil.isNotBlank(sysLog.getType())) {
            wrapper.eq(SysLogDO::getType, sysLog.getType());
        }

        if (ArrayUtil.isNotEmpty(sysLog.getCreateTime())) {
            wrapper.ge(SysLogDO::getCreateTime, sysLog.getCreateTime()[0]).le(SysLogDO::getCreateTime,
                    sysLog.getCreateTime()[1]);
        }
        return this.baseMapper.selectPage(new Page<>(page.getPageNum(), page.getPageSize()), wrapper);
    }

}
